﻿namespace InheritanceAndPolymorphism
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    internal class OffsiteCourse : Course
    {
        private string town;

        public OffsiteCourse()
            : this(null)
        {
        }

        public OffsiteCourse(string name)
            : this(name, null)
        {
        }

        public OffsiteCourse(string name, string teacherName)
            : this(name, teacherName, null)
        {
        }

        public OffsiteCourse(string name, string teacherName, IList<string> students)
            : this(name, teacherName, students, null)
        {
        }

        public OffsiteCourse(string name, string teacherName, IList<string> students, string townName)
            : base(name, teacherName, students)
        {
            this.Town = townName;
        }

        internal string Town
        {
            get
            {
                return this.town;
            }

            private set
            {
                if (value != null)
                {
                    if (value.Length < 2)
                    {
                        throw new ArgumentException("Invalid town name length");
                    }
                }
                
                this.town = value;
            }
        }

        public override string ToString()
        {
            StringBuilder result = new StringBuilder(base.ToString());
            
            if (this.Town != null)
            {
                result.Append("; Town = ");
                result.Append(this.Town);
            }

            result.Append(" }");

            return result.ToString();
        }
    }
}